package com.hsylient.javase.chapter11.demo07;

import lombok.SneakyThrows;

/**
 * 在主线程中进行循环打印（数数）
 * 在子线程中先让子线程睡1秒，保证主线程可以先抢到时间片，先把循环跑起来
 * 然后让子线程去插队
 */
public class JoinThreadTest {
    @SneakyThrows
    public static void main(String[] args) {
        Thread thread = new Thread(new JoinThread());
        thread.start();
        for (int i = 0; i < 10009; i++) {
            System.out.println(Thread.currentThread().getName() + "主线程在数数：" + i);
            if (i == 500) {
                thread.join();
            }
        }
    }
}
